package jp.peach_boys.sandbox.slim3.entity;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Datastore;
import org.slim3.datastore.Model;

import com.google.appengine.api.datastore.Key;

@Model
public class Image {
    @Attribute(primaryKey = true)
    private Key key;
    private String rcd;
    private String filename;
    
    @Attribute(lob = true)
    private byte[] image;
    public Key getKey() {
        return key;
    }
    public void setKey(Key key) {
        this.key = key;
    }
    public String getRcd() {
        return rcd;
    }
    public void setRcd(String rcd) {
        this.rcd = rcd;
    }
    public byte[] getImage() {
        return image;
    }
    public void setImage(byte[] image) {
        this.image = image;
    }
    public String getFilename() {
        return filename;
    }
    public void setFilename(String filename) {
        this.filename = filename;
    }
    public static Image getImageByFilename(String filename){
        ImageMeta meta = ImageMeta.get();
        Image image = Datastore.query(meta).filter(meta.filename.equal(filename)).asSingle();
        return image;
    }
    public static Image getImageByRcd(String rcd){
        ImageMeta meta = ImageMeta.get();
        Image image = Datastore.query(meta).filter(meta.rcd.equal(rcd)).asSingle();
        return image;
    }
}
